package reflectdemo;

class Student {

    private String name = "zhangsan";

    public int age = 20;

    public Student() {
        System.out.println("Student()");
    }

    private Student(String name, int age) {
        this.name = name;
        this.age = age;
        System.out.println("Student(String, int)");
    }

    private void eat(){
        System.out.println("i am eat");
    }

    public void sleep(){
        System.out.println("i am pig");
    }

    private void function(String str) {
        System.out.println(str);
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}

public class Test1 {
    public static void main(String[] args) {
        // 通过实例获取
        Student student = new Student();
        Class<?> c1 = student.getClass();

        // 直接通过类名创建对象
        Class<?> c2 = Student.class;
        // 通过forName全路径名创建对象
        Class<?> c3 = null;
        try {
            c3 = Class.forName("reflectdemo.Student");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }

        // 全部为 true，说明一个类对应一个Class对象
        System.out.println(c1 == c2);
        System.out.println(c1 == c3);
        System.out.println(c2 == c3);

    }
}
